home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWCHARAC_H
- #define FWCHARAC_H
- //========================================================================================
- //
- // File: FWCharac.h
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- // Native Character sets are determined by two parameters: 1) maximum character size,
- // and 2) fixed vs. variable width characters. If characters are fixed width, then
- // all characters are maximum character size in width.
- //
- // This strings component also uses a "median" character size value when dealing with
- // variable width characters. In all variable width systems we're aware of, the median
- // value should be 2 bytes. This median value is used in one place: computing
- // the capacity of a bounded string from the template capacity parameter.
- //
- // Note that all strings are terminated with a "NUL" character, which is a FW_Char(0).
- // This may be more zero bytes than necessary in some characters sets, but it's a simple
- // and safe rule to follow.
-
- #if defined FW_BYTE_CHARACTERS
- typedef char FW_Char;
- #elif defined FW_SHORT_CHARACTERS
- typedef short FW_Char;
- #elif defined FW_LONG_CHARACTERS
- typedef long FW_Char;
- #else
- typedef char FW_Char; // default to byte wide
- #define FW_BYTE_CHARACTERS
- #endif
-
- typedef unsigned char FW_PascalChar;
-
- typedef unsigned char FW_Byte;
- typedef long FW_CharacterCount;
- typedef long FW_CharacterPosition;
-
- typedef long FW_ByteCount;
- typedef long FW_BytePosition;
-
- enum {FW_kNulCharacter=0};
-
- #ifdef FW_VARIABLE_WIDTH_CHARACTERS
- enum {FW_kMedianCharacterSize=2};
- #else
- enum {FW_kMedianCharacterSize=sizeof(FW_Char)};
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_StringLength
- //----------------------------------------------------------------------------------------
-
- FW_CharacterCount FW_StringLength(const FW_Char * string);
-
- //----------------------------------------------------------------------------------------
- // FW_BlockMove
- //----------------------------------------------------------------------------------------
-
- void FW_BlockMove(const FW_Byte *source, FW_Byte *destination, FW_ByteCount numberBytes);
-
- //========================================================================================
- // ----- Utility functions for byte <==> character mapping
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_BytesInString
- //----------------------------------------------------------------------------------------
-
- FW_ByteCount FW_BytesInString(const void* string, FW_CharacterCount length);
- // Returns number of bytes in string.
- // For fixed-width character sets this function does not examine the string,
- // so it is very fast.
- // For variable-width character sets this function searches the string,
- // so it might be slow!
-
- //----------------------------------------------------------------------------------------
- // FW_BytePositionInString
- //----------------------------------------------------------------------------------------
-
- FW_Byte* FW_BytePositionInString(const void* string, FW_CharacterCount position);
- // Returns pointer to given character in string.
- // Uses FW_BytesInString(), so same notes apply.
-
- //----------------------------------------------------------------------------------------
- // FW_CharactersInBlock
- //----------------------------------------------------------------------------------------
-
- FW_CharacterCount FW_CharactersInBlock(const void *block, FW_ByteCount length);
- // Returns number of characters in block of bytes.
- // For fixed-width character sets this function does not examine the string,
- // so it is very fast.
- // For variable-width character sets this function searches the string,
- // so it might be slow!
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- FW_Byte* FW_PreviousCharacter(FW_Byte* string, FW_Byte* current, short delta=1);
- // A potentially very slow routine for backing up through a string.
- // string and current must be pointers into the same string, each
- // pointing at the first byte of a character, and string < current.
- // The function result is a pointer to the character delta positions before the character
- // at current, i.e. current decremented by the number of bytes in the delta previous characters.
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- const FW_Byte* FW_PreviousCharacter(const FW_Byte* string, const FW_Byte* current, short delta=1);
- // The const version of the above function.
-
- //----------------------------------------------------------------------------------------
- // FW_BlockMove
- //----------------------------------------------------------------------------------------
-
- inline void FW_BlockMove(const FW_Byte *source, FW_Byte *destination, FW_ByteCount numberItems)
- {
- FW_PrimitiveCopyMemory(source, destination, numberItems);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_BytesInString
- //----------------------------------------------------------------------------------------
-
- inline FW_ByteCount FW_BytesInString(const void* string, FW_CharacterCount length)
- {
- #ifdef FW_VARIABLE_WIDTH_CHARACTERS
- // ???JEL - Need to call operating system here
- return NotYetImplemented();
- #else
- return length*sizeof(FW_Char);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CharactersInBlock
- //----------------------------------------------------------------------------------------
-
- inline FW_CharacterCount FW_CharactersInBlock(const void *block, FW_ByteCount length)
- {
- #ifdef FW_VARIABLE_WIDTH_CHARACTERS
- // ???JEL - Need to call operating system here
- return NotYetImplemented();
- #else
- return length/sizeof(FW_Char);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- inline FW_Byte* FW_PreviousCharacter(FW_Byte* string, FW_Byte* current, short delta)
- {
- #ifdef FW_VARIABLE_WIDTH_CHARACTERS
- return string +
- FW_BytesInString(string, FW_CharactersInBlock(string, current-string)-delta);
- #else
- return current - sizeof(FW_Char)*delta;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PreviousCharacter
- //----------------------------------------------------------------------------------------
-
- inline const FW_Byte* FW_PreviousCharacter(const FW_Byte* string, const FW_Byte* current, short delta)
- {
- #ifdef FW_VARIABLE_WIDTH_CHARACTERS
- return string +
- FW_BytesInString(string, FW_CharactersInBlock(string, current-string)-delta);
- #else
- return current - sizeof(FW_Char)*delta;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_BytePositionInString
- //----------------------------------------------------------------------------------------
-
- inline FW_Byte* FW_BytePositionInString(const void* string, FW_CharacterCount position)
- {
- return (FW_Byte*) string + FW_BytesInString(string, position);
- }
-
- #endif
-
-